﻿
namespace First_WebAPI.HostedServices
{
    public class HostedService1 : BackgroundService
    {
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            int i = 0;
            while (true)
            {
                Console.WriteLine(DateTime.Now.ToString());
                await Task.Delay(5000);
                i++;
                //故意制造异常
                //if (i > 3)
                //{
                //    throw new TimeoutException();
                //}
            }
        }
    }
}
